<?php
class Facebook
{
  public static function post($share)
  {
    $page_id = '182974521721759';
    $page_access_token = '116487325090582|326e6f23b427d938a1eefed7-533936499|182974521721759|dlRfci1bKYcfCYS8KhhOvWgduVg';
    
    if($page_id && $page_access_token)
    {
      // create a new cURL resource
      $ch = curl_init();
      // set URL and other appropriate options
      curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/".$page_id."/feed");
      curl_setopt($ch, CURLOPT_HEADER, false);
      curl_setopt($ch, CURLOPT_POST, true);
      $data = array(
        'access_token' => $page_access_token,
        'link' => $share->getUrl(),
        'picture' => $share->getImage(),
        'name' => $share->getTitle(),
        'description' => $share->getBody()
      );
      curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

      // grab URL and pass it to the browser
      $response = curl_exec($ch);

      // close cURL resource, and free up system resources
      curl_close($ch);
       
      return json_decode($response);
    }
  }
}
